package zzg.study.reactor;

import java.nio.channels.Selector;

/**
 * @Classname ServiceThread
 * @Description TODO
 * @Date 2025/1/27 16:14
 * @Author zhuzhenguo
 */
public abstract class ServiceThread extends Thread {

    protected Selector selector;

    public ServiceThread(String name) {
        super(name);
        try {
            selector = Selector.open();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    protected void closeSelector() {
        if (selector != null) {
            try {
                this.selector.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    protected void wakeupSelector() {
        if (selector != null) {
            this.selector.wakeup();
        }
    }


}
